# This my first django Dockerfile
# Version 1.0
# Base images 基础镜像
FROM centos:centos7.5.1804
#MAINTAINER 维护者信息
LABEL maintainer="wyzerg@163.com"
#ENV 设置环境变量
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
#RUN 执行以下命令
RUN curl -so /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo && rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
RUN yum install -y  python36 python3-devel gcc pcre-devel zlib-devel make net-tools nginx
#工作目录 docker exec 进入容器也默认在workdir目录
WORKDIR /opt/luffyapi
#拷贝 当前的本地文件 至 容器的工作目录
COPY . .

#安装依赖的插件
RUN pip3 install -i https://pypi.douban.com/simple/ https://codeload.github.com/sshwsfc/xadmin/zip/django2
RUN pip3 install -i https://pypi.douban.com/simple --trusted-host mirrors.aliyun.com -r requirments.txt
RUN chmod +x run.sh && rm -rf ~/.cache/pip

# django 的mysql报错的bug解决
RUN sed -i "s/if version < (1, 3, 13):/#/g"  /usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py && sed -i "s/    raise ImproperlyConfigured('mysqlclient 1.3/#/g"  /usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py

# django 的decode报错解决
RUN sed -i "s/query = query.decode(errors='replace')/query = query.encode(errors='replace')/g" /usr/local/lib/python3.6/site-packages/django/db/backends/mysql/operations.py

# 拷贝nginx配置文件
COPY luffyapi.conf /etc/nginx

#EXPOSE 映射端口
EXPOSE 8000
#容器启动时执行命令
CMD ["./run.sh"]
